package com.net.shop.car.manager.api.volley.response.dingdan;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.net.shop.car.manager.api.model.TuiKuanDingdan;
import com.net.shop.car.manager.api.volley.Response;
import com.net.shop.car.manager.utils.Constants;
import com.net.shop.car.manager.utils.StringUtils;

public class DingdanTuikunListResponse extends Response {

	private int totalPages;
	private List<TuiKuanDingdan> tuiKuanDingdans;

	public DingdanTuikunListResponse() {
		super(Constants.DINGDAN_TUIKUN_LIST);
	}

	@Override
	public String[] getContentTags() {
		return new String[] { "totalpages", "orderlist" };
	}

	@Override
	public void parseContent(String content, int index) {
		if (index == 0) {
			totalPages = StringUtils.filterIntegerNull(content);
		} else if (index == 1) {
			JSONArray jsonArray;
			try {
				jsonArray = new JSONArray(content);
				tuiKuanDingdans = new ArrayList<TuiKuanDingdan>();
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject jsonObject = jsonArray.getJSONObject(i);
					TuiKuanDingdan dingDan = new TuiKuanDingdan();
					dingDan.setCreateDate(StringUtils.filterNull(jsonObject
							.getString("CREATE_DATE")));
					dingDan.setGoodName(StringUtils.filterNull(jsonObject
							.getString("GOOD_NAME")));
					dingDan.setId(StringUtils.filterNull(jsonObject
							.getString("ID")));
					dingDan.setOrderId(StringUtils.filterNull(jsonObject
							.getString("ORDER_ID")));
					dingDan.setRefundDes(StringUtils.filterNull(jsonObject
							.getString("REFUND_DESC")));
					dingDan.setRefundState(StringUtils
							.filterIntegerNull(jsonObject
									.getString("REFUND_STATE")));
					tuiKuanDingdans.add(dingDan);
				}
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

	public int getTotalPages() {
		return totalPages;
	}

	public List<TuiKuanDingdan> getTuiKuanDingdans() {
		return tuiKuanDingdans;
	}

}
